# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from baseclass import BaseClass

class restore_bad_send(BaseClass):
    def test_restore_bad_send(self):
        print sys.getdefaultencoding()
        driver = self.driver
        #Link to auth
        inputElement = driver.find_element_by_css_selector("div.b-header-top-auth")\
                             .find_element_by_css_selector("span.g-pseudo-h")
        inputElement.click()
        #Auth popup
        auth_pop = self.wait_for_popub_name(u'Авторизация')
        #Restore link
        restbs = WebDriverWait(auth_pop, timeout=3)\
                .until(lambda dr: dr.find_elements_by_css_selector("span.g-pseudo-h"))
        restb = [rg for rg in restbs if rg.get_attribute("textContent")==u'восстановить'][0]
        restb.click()
        #Restore popup
        rest_pop = WebDriverWait(driver, timeout=10)\
                  .until(lambda dr: dr.find_element_by_css_selector(self.variables.rest_sel))\
                  .find_element_by_css_selector("div.b-popup-h")
        #Send credentials
        send_btn = rest_pop.find_elements_by_css_selector("input.b-sbutton-input")[0]
        inp_mail = rest_pop.find_element_by_name('value')
        inp_mail.send_keys(randomword(3,15))
        send_btn.click()
        #Error tooltip
        self.find_error_tooltip(rest_pop, u'Неверно указан адрес электронной почты')
